﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using CityWeather.Resources;

namespace CityWeather
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
                    
        }

        private void ApplicationBarIconButton_Click(object sender, EventArgs e)
        {

            var vm = this.Resources["ViewModel"] as ViewModel.CityWeatherViewModel;

            NavigationService.Navigate(new Uri("/View/ConfigPage.xaml?Pais=" + vm.Pais + "&Ciudad=" + vm.Ciudad + "&Actualizar=" + vm.Actualizar.ToString(), UriKind.Relative));
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            var vm = this.Resources["ViewModel"] as ViewModel.CityWeatherViewModel;
            string val;
            if (NavigationContext.QueryString.TryGetValue("Pais", out val))
            {
                vm.Pais = NavigationContext.QueryString["Pais"];
                vm.Ciudad = NavigationContext.QueryString["Ciudad"];
                vm.Actualizar = Boolean.Parse(NavigationContext.QueryString["Actualizar"]);
                vm.UpdateSettings();
            }
           
            vm.getData();
        }

    }
}